use crate::utils::MathError;

pub fn calculate(num1: f64, num2: f64, operator: &str) -> Result<f64, MathError> {
    match operator {
        "+" => Ok(num1 + num2),
        "-" => Ok(num1 - num2),
        "*" => Ok(num1 * num2),
        "/" => {
            if num2 == 0.0 {
                Err(MathError::DivisionByZero)
            } else {
                Ok(num1 / num2)
            }
        }
        _ => Err(MathError::InvalidOperator(operator.to_string())),
    }
}